/*
 * @Author: HotSuitor
 * @Date: 2020-03-12 11:26:33
 * @LastEditors: hs
 * @LastEditTime: 2020-03-12 12:22:24
 * @Description: hotsuitor@qq.com
 */
package main

import (
	"fmt"
)

func main() {
	var slice1 []int
	slice1 = []int{1,2,3,4,5,6}
	slice2 := make([]int, 3, 5)
	fmt.Printf("切片数据：%v，长度：%d，最大长度: %d\n",slice1, len(slice1), cap(slice1))
	printSlice(slice2)
	// append向切片中添加元素和copy复制切片

	var numbers []int
	printSlice(numbers)

	// 允许追加空切片
	numbers = append(numbers,0)
	printSlice(numbers)

	// 向切片添加一个元素
	numbers = append(numbers, 1)
	printSlice(numbers)

	// 向切片添加多个元素
	numbers = append(numbers, 2,3,4)
	printSlice(numbers)

	// 创建切片 numbers1 为 numbers 容量的两倍
	numbers1 := make([]int, len(numbers), cap(numbers)*2)
	printSlice(numbers1)

	// 复制切片
	copy(numbers1, numbers)
	printSlice(numbers1)
}

func printSlice(slice []int) {
	fmt.Printf("slice=%v，len=%d，cap=%d\n",slice, len(slice), cap(slice))
}
